package com.sky.service.impl;

import com.sky.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ShopServiceImpl implements ShopService {

    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public String setStatus(Integer status) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
            if (status == 1){
                valueOperations.set("SHOP_STATUS",1);
                return "店铺已开启";
            }else {
                valueOperations.set("SHOP_STATUS",0);
                return "店铺已关闭";
            }
    }

    @Override
    public Integer getStatus() {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status= (Integer) valueOperations.get("SHOP_STATUS");
        if (status==null){
            return 0;
        }
        if (status==1){
            return 1;
        }
        return 0;
    }
}
